//
//  AlertViewExtension.m
//  AlertView
//
//  Created by alive on 2017/2/4.
//  Copyright © 2017年 刘学丽. All rights reserved.
//

#import "AlertViewExtension.h"

@implementation AlertViewExtension


-(instancetype)initWithFrame:(CGRect)frame
{
    self =[super initWithFrame:frame];
    if (self) {
        //设置模板层背景色
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];

        
        _tipebackView =[[UIView alloc]initWithFrame:CGRectMake(30, (KScreenHeight-150)/2, KScreenWidth-40, 150)];
        _tipebackView.backgroundColor=[UIColor whiteColor];
        _tipebackView.layer.cornerRadius=15;
        _tipebackView.layer.masksToBounds = YES;
        [self addSubview:_tipebackView];
        
        
        _tipeLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, 10, _tipebackView.frame.size.width-20, _tipebackView.frame.size.height-20)];
        _tipeLabel.textAlignment=NSTextAlignmentCenter;
        _tipeLabel.numberOfLines= 0;
        [_tipebackView addSubview:_tipeLabel];
        
        
        _cancelBtn  =[UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.tag=0;
        [_cancelBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:ColorI(0x2e353f) forState:UIControlStateNormal];
        _cancelBtn.titleLabel.font =[UIFont systemFontOfSize:17 weight:0.5];
        [_cancelBtn addTarget:self action:@selector(btnClickSelector:) forControlEvents:UIControlEventTouchUpInside];
        _cancelBtn.backgroundColor =[UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1.0];
        [_tipebackView addSubview:_cancelBtn];
        

        
        
        _sureBtn  =[UIButton buttonWithType:UIButtonTypeCustom];
        _sureBtn.tag=1;
        [_sureBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_sureBtn setTitleColor:ColorI(0x2e353f) forState:UIControlStateNormal];
        _sureBtn.titleLabel.font =[UIFont systemFontOfSize:17 weight:0.5];
        [_sureBtn addTarget:self action:@selector(btnClickSelector:) forControlEvents:UIControlEventTouchUpInside];
        _sureBtn.backgroundColor =[UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1.0];
        [_tipebackView addSubview:_sureBtn];
        
        
        _linLab = [[UILabel alloc] init];
        _linLab.backgroundColor = RGB(222, 222, 222);
        [_tipebackView addSubview:_linLab];
    }
    return self;
}

//设置提示view的宽高
-(void)setbackviewframeWidth:(CGFloat)width Andheight:(CGFloat)height
{
    CGFloat tipeheight =(self.frame.size.height-height)/2;
    CGFloat tipewidth=(self.frame.size.width-width)/2;
    _tipebackView.frame=CGRectMake(tipewidth, tipeheight, width, height);
    _tipeLabel.frame=CGRectMake(0, 0, _tipebackView.frame.size.width, _tipebackView.frame.size.height-55);
    _cancelBtn.frame=CGRectMake(0, _tipebackView.frame.size.height-55, width/2, 55);
    _sureBtn.frame=CGRectMake(width/2, _tipebackView.frame.size.height-55, width/2, 55);
    _linLab.frame = CGRectMake(width/2-1, _tipebackView.frame.size.height-52, 1, 52);

}
//设置提示语
-(void)settipeTitleStr:(NSString *)tipeStr Andfont:(CGFloat)font
{
    _tipeLabel.font=FontP(17);
    _tipeLabel.backgroundColor = Colorbackground;
    _tipeLabel.text=tipeStr;
    _tipeLabel.textColor = ColorI(0x2e353f);
    
    
}

//按钮方法
-(void)btnClickSelector:(UIButton *)btn
{
    if ([self.delegate respondsToSelector:@selector(clickBtnSelector:)]) {
        [self.delegate clickBtnSelector:btn];
    }
}
@end
